<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Forgotpassword extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('url');
    }

    function index()
    {
        $this->load->view('forgot-password/header.php');
        $this->output('forgot-password/stepOne.php');
        $this->load->view('forgot-password/footer.php');
    }
    

    function sendEmail()
    {
        $this->load->model('user');
        $this->load->library('email');
        $config = array(
            'protocol' => 'sendmail',
            'mailtype' => 'html',
            'Return-Path' => '/'
        );
        $this->load->view('forgot-password/header.php');
        $this->email->initialize($config);
        $handle = $this->user->getPasswordByEmail($this->input->post('email'));
        if (!empty($handle)) {
            $this->email->from('info@XXXX.com', 'Sitio Web XXX');
            $this->email->to($this->input->post('email'));
            $this->email->subject('Recuperar Contraseña');
            $html = '<html><head></head><body><table>';
            $html .= '<tr><td><p>Su solicitud de recuperar contraseña fue solicitada, sus datos a continuacion:</p></td></tr>';
            $html .= '<tr><td><p>Username :' . $handle->email . '</p></td></tr>';
            $html .= '<tr><td><p>Password :' . $handle->password . '</p></td></tr>';
            $html .= '</table></body></html>';
            $this->email->message($html);
            $exito = $this->email->send();
            
        } else {
            $exito = false;
        }
        $this->output('forgot-password/stepOne.php', array('send' => $exito));
        $this->load->view('forgot-password/footer.php');
    }
    
    function output($view, $output = null)
    {
        $this->load->view($view,$output);	
    }
}
?>